<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onRowSelectChange="selectChange"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getgraphicAndAssemblyInfoPage,getGraphicModelList,getGraphicSystemList} from '@/api/graphic/catalogue/index';
import { getUserId } from '@/assets/js/auth'

export default {
  name: 'rcatalogueManage',
  mixins: [dictionary],
  data() {
    return {
      showAdd:false,
      showImport: false,
      modelName:'',
      systemName:'',
      systemCode: '',
      modelCode: '',
      okstate:'',
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: getgraphicAndAssemblyInfoPage,
      fetchParams: { xhrAbort: true },
      visibleDrawer: false,
      handleType: '',
      formData: {},
      title: '',
      initData: {},
      partinfos: {},
      rowSelectData: [],
      saveData: null
    };
  },
  methods: {

    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: '物料代码',
          fieldName: 'graphicCode'
        },
        {
          type: 'INPUT',
          label: '物料名称',
          fieldName: 'graphicName'
        },
       {
         type: 'INPUT',
         label: '车型代码',
         fieldName: 'modelCode'
       },
        {
          type: 'SELECT',
          label: '车型名称',
          fieldName: 'modelName',
          placeholder: '请选择...',
          itemList: this.getGraphicModelArray()
        },
        {
          type: 'INPUT',
          label: '系统代码',
          fieldName: 'systemCode'
        },
        {
          type: 'SELECT',
          label: '系统名称',
          fieldName: 'systemName',
          placeholder: '请选择...',
          itemList: this.getGraphicSystemArray()
        },
      ];
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {title: '车型代码', dataIndex: 'modelCode', sorter: true},
        {title: '车型名称', dataIndex: 'modelName', sorter: true },
        {title: '系统代码', dataIndex: 'systemCode', sorter: true },
        {title: '系统名称', dataIndex: 'systemName', sorter: true },
        {title: '物料代码', dataIndex: 'graphicCode', sorter: true },
        {title: '物料名称', dataIndex: 'graphicName' , sorter: true},
        {title: '单元用量', dataIndex: 'unitAmount', sorter: true },
        // {title: '三级代码', dataIndex: 'threeMenu', sorter: true },
        // {title: '二级代码', dataIndex: 'twoMenu' , sorter: true},
        {title: '上级代码', dataIndex: 'oneMenu', sorter: true },
        {
          title: '是否备件',
          dataIndex: 'isSpare',
          editable: true,
          defaultEditable: true,
          filterItems: this.createDictList('1004'),
          filterType: 'radio',
          editType: 'checkbox',
           disabled:true,
          editItems: [
            { text: '', trueValue: 10041001 },
            { text: '', falseValue: 10041002 }
          ]
        }
      ];
    },
    selectChange(val) {
      this.rowSelectData = val;
    },

    getGraphicModelArray() {
     // debugger;
      let res = [];
      getGraphicModelList().then(response => {
        response.data.forEach(x => {
          res.push({text:x.modelName, value:x.modelName});
        });
      });
      return res;
    },
  getGraphicSystemArray() {
      let res = [];
      getGraphicSystemList().then(response => {
        response.data.forEach(x => {
          res.push({text:x.systemName, value:x.systemName});
        });
      });
      return res;
    },

    changeHandle(val) {
      let params = Object.assign({}, val, { xhrAbort: false });
      if (params.bjsycx && params.bjsycx != null && params.bjsycx.length > 0) {
        params.bjsycx = params.bjsycx.join(",");
      }
      // this.fetchParams = Object.assign({}, val);
      this.fetchParams = params;
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
};
</script>

<style scoped></style>
